package net.jwtools.tmt.ui.util;

import java.util.ArrayList;
import java.util.List;

import org.flexdock.docking.DockingConstants;
import org.flexdock.docking.state.DockingState;
import org.flexdock.perspective.LayoutSequence;
import org.flexdock.perspective.Perspective;
import org.flexdock.perspective.PerspectiveFactory;

public class MainPerspectiveFactory implements PerspectiveFactory {

    public Perspective getPerspective(String perspectiveId) {
        List<DockingState> dss = new ArrayList<DockingState>();

        DockingState ds = new DockingState("checkoutView");
        ds.setRegion(DockingConstants.CENTER_REGION);
        ds.setSplitRatio(.60f);
        dss.add(ds);

        ds = new DockingState("checkinView");
        ds.setRegion(DockingConstants.CENTER_REGION);
        ds.setRelativeParentId("checkoutView");
        ds.setSplitRatio(.60f);
        dss.add(ds);

        ds = new DockingState("homeView");
        ds.setRegion(DockingConstants.CENTER_REGION);
        ds.setRelativeParentId("checkoutView");
        ds.setSplitRatio(.60f);
        dss.add(ds);
        
        ds = new DockingState("buttonBarView");
        ds.setRegion(DockingConstants.WEST_REGION);
        ds.setRelativeParentId("homeView");
        ds.setSplitRatio(.40f);
        dss.add(ds);

        // ... more views here
        
        return createPerspective("myDefaultPerspective", dss);
    }

    private Perspective createPerspective(String perspectiveId, java.util.List<DockingState> dockingStates) {
        Perspective perspective = new Perspective(perspectiveId, perspectiveId);
        LayoutSequence sequence = perspective.getInitialSequence(true);
        for (DockingState dockingState : dockingStates) {
            if( dockingState.getRelativeParentId() != null)
                sequence.add(dockingState.getDockableId(), dockingState.getRelativeParentId(), dockingState.getRegion(), dockingState.getSplitRatio());
            else
                sequence.add(dockingState.getDockableId());
        }
        return perspective;
    }
    
//    public void afterPropertiesSet() throws Exception {
//        Assert.notEmpty(this.dockableIds, "No dockable ids specified");
//    }
//
//    public List<String> getDockableIds() {
//        return dockableIds;
//    }
//
//    public void setDockableIds(List<String> dockableIds) {
//        this.dockableIds = dockableIds;
//    }
}